#include "ActorComponent.h"

#include "Runtime/Logic/World.h"

namespace Alice
{
    ActorComponent::ActorComponent()
    {
        mbRegistered=false;
        mbAutoRegister=true;
        mbHasBeenCreated=false;
        mbRenderStateCreated=false;
    }
    void ActorComponent::RegisterComponent()
    {
        RegisterComponentWithWorld(GetWorld());
    }
    void ActorComponent::UnregisterComponent()
    {
        
    }
    void ActorComponent::ExecuteRegisterEvents(FRegisterComponentContext* Context)
    {
        if(!mbRegistered)
        {
            OnRegister();
        }
        if(!mbRenderStateCreated)
        {
            CreateRenderState_Concurrent(Context);
        }
    }
    void ActorComponent::OnRegister()
    {
        mbRegistered=true;
    }

    void ActorComponent::OnComponentCreated()
    {
        mbHasBeenCreated=true;
    }
    void ActorComponent::RegisterComponentWithWorld(World* inWorld, FRegisterComponentContext* Context)
    {
        OnComponentCreated();
        mWorldPrivate=inWorld;
        ExecuteRegisterEvents(Context);
    }
    void ActorComponent::MarkRenderTransformDirty()
    {
        MarkForNeededEndOfFrameUpdate(); 
    }
    void ActorComponent::MarkForNeededEndOfFrameUpdate()
    {
        mWorldPrivate->MarkActorComponentForNeededEndOfFrameUpdate(this,false);
    }
    void ActorComponent::CreateRenderState_Concurrent(FRegisterComponentContext* Context)
    {
        mbRenderStateCreated=true;
    }
    void ActorComponent::DestroyRenderState_Concurrent()
    {
        
    }
    void ActorComponent::SendRenderTransform_Concurrent()
    {
        mbRenderTransformDirty=false;
    }
    void ActorComponent::SendRenderDynamicData_Concurrent()
    {
        
    }
    void ActorComponent::SendRenderInstanceData_Concurrent()
    {
        
    }
    void ActorComponent::TickComponent(float DeltaTime, ELevelTick TickType)
    {
        
    }
    void ActorComponent::DoDeferredRenderUpdates_Concurrent()
    {
        if(mbRenderTransformDirty)
        {
            SendRenderTransform_Concurrent();
        }
    }

}
